// pages/gerenxinxi/gerenxinxi.js

import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    touxiang: '',
    userxinxi:""
  },

  uploadMedical: function () {
    var that = this
    wx.showActionSheet({
      itemList: ['从相册选取', '拍照'],
      success(res) {
        var index = res.tapIndex;
        var dogphoto = that.data.dogphoto;
        if (index == 0) {
          let num = 1; //一次最大上传九张
          wx.chooseImage({
            count: num,
            sizeType: ['original', 'compressed'],
            sourceType: ['album'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片
              const tempFilePaths = res.tempFilePaths;
              console.log(tempFilePaths)
              var touxiang = tempFilePaths[0]

              that.setData({
                touxiang: touxiang
              });
              that.shangchuantp()

            }
          })
        } else if (index == 1) {
          wx.chooseImage({
            count: 1,
            sizeType: ['original', 'compressed'],
            sourceType: ['camera'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片
              const tempFilePaths = res.tempFilePaths;
              var touxiang = tempFilePaths[0]

              that.setData({
                touxiang: touxiang
              });
              that.shangchuantp()
            }
          })
        }

      },
      fail(res) {
        console.log(res.errMsg)
      }
    })

  },

  shangchuantp: function () {
    // wx.uploadFile({
    //   url: 'https://xfz.897xls.cn/api/PersonDetails/Update?', //仅为示例，非真实的接口地址
    //   filePath: this.data.touxiang,
    //   name: 'PersonImg',
    //   formData: {
    //     // PersonImg: this.data.touxiang,
    //     'token': wx.getStorageSync('Access_token'),
    //   },
    //   success(res) {
    //     const data = res.data
    //     //do something
    //   }
    // })
    console.log("上传")
  },

  toupname:function(){
    wx.navigateTo({
      url: '/pages/xiugai/xiugai',
    })
  },

  getuserxinxi: function () {
    ajax('/wxUserInfo', {
      data: {
        sessionKey: wx.getStorageSync("sessionKey"),
        encryptedData: wx.getStorageSync("encryptedData"),
        iv: wx.getStorageSync("iv"),
      },
      header: {
        'Accept': 'application/json', // 默认值
      },
      method: 'post'
    }, res => {
      console.log(res)
      this.setData({
        userxinxi: res.data
      })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getuserxinxi()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    wx.stopPullDownRefresh()
  }
})